1. Field of the Invention
The present invention relates generally to a data processing system and in particular to a method and apparatus for accessing a library. More particularly, the present invention is directed to a computer-implemented method, apparatus, and computer-usable program code for accessing a compatible library to execute an executable that references a library.
2. Description of the Related Art
Executables in a data processing system often reference one or more libraries while loading or executing. A library is a collection of functions, subprograms, methods, procedures, subroutines, data, or any combination thereof. Because a single library may be referenced by different applications, the functions contained in a library may be easily reused. Examples of libraries include the C standard library, the standard input/output library, and libraries containing math functions, string handling functions, and time manipulation functions. Examples of operating systems that support the use of libraries include Advanced Interactive executive (AIX), Unix, and Microsoft® Windows®. AIX is available from International Business Machines Corporation. Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.
Unlike a static library, from which functions are copied into an application at the time of compilation, a dynamic, or shared, library contains functions that remain in a separate file on a storage medium. Executables may contain one or more library references to a dynamic library. For example, a library reference may be designated by an absolute path, such as “/usr/lib/libc.a”, or a relative path, such as “libc.a”. At the time the executable is either loaded or executed, a loader, which is part of the underlying operating system, links the referenced library to the executable. The executable may then utilize the library contained in the library reference.
A primary advantage of using a dynamic library is that the library functions are not copied directly into an application. Therefore, an updated or improved version of the functions in the dynamic library may be referenced by the executable using the same library reference. Unless indicated otherwise, the term “library,” as used below, is intended to indicate a dynamic, or shared, library.
Before an executable can access a library, the library must be loaded onto the shared library segment, which may be located on a computer's primary memory. The loader loads a referenced library onto the shared library segment from a secondary memory. Secondary memory is used to store data that is not currently in active use. An example of secondary memory is a hard drive. A different version of a library may be loaded onto the shared library segment alongside the already loaded original version. However, if the referenced library that is being loaded onto the shared library segment from the secondary memory is unavailable, the executable containing the corresponding library reference will fail to execute.
A library can be unavailable for any of a variety of reasons. For example, a library may be unavailable if the library is incompatible. A library may be incompatible for an executable if the library fails to resolve the symbols, functions, or variables used by the executable. A library may also be incompatible if the particular version of the library is incompatible with the kernel of the operating system. A library may be incompatible if dependent libraries fail to export functions or data that are referenced by the library on which the dependent library depends. A corrupt library also can prevent an executable from executing. A library may be unavailable if the library is absent from the secondary memory. For example, the referenced library may have been accidentally deleted from the secondary memory by a user.
In addition to command execution failure, complete system failure may also result from the presence of an incompatible library on the secondary memory. Further, if the incompatible library is itself needed to recover from the system failure, then the user may have no choice except to reboot or even reinstall the system. For example, the commands that reference the C standard library, many of which are critical to the operation of a computer system, will fail to execute if the C standard library is incompatible, possibly resulting in system failure. In addition, the commands needed to recover from the system failure will be unable to execute because the recovery commands also require the C standard library. Therefore, reinstallation of the system may be necessary to restore the C standard library and other critical libraries onto the system.
Current systems attempt to recover from a failed executable by providing a statically-linked executable that substitutes the failed dynamically-linked executable. However, this approach provides redundant executables because both a statically-linked executable and a dynamically-linked executable must be provided. In addition, the effectiveness of the current solution is limited to the number of statically-linked commands provided by a particular vendor for a special case.
Another approach used by current systems stores duplicate copies of critical libraries, such as the C standard library, in paths that are hidden to a user. Library references are redirected to the duplicate copies by providing a command that sets an environment variable. However, this approach fails if the duplicate copies of the libraries are themselves lost or corrupted.